<template>
  <div class="evaluate-list">
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        :error.sync="error"
        error-text="请求失败，点击重新加载"
        @load="onLoad"
      >
        <div
          class="item"
          v-for="(item, index) in result"
          :key="item.id || index"
          @click="goToDetail(item)"
        >
          <div class="item-title">{{ item.courseName }}</div>
          <div class="item-info">授课老师：{{ item.evaluator }}</div>
          <div class="item-time">上课时间：{{ item.startTime }}</div>
        </div>
      </van-list>
    </van-pull-refresh>

    <div class="nodata" v-if="!loading && result.length === 0 && !error">
      <van-empty description="暂无数据哦" />
    </div>
  </div>
</template>

<script>
import { Empty, List, PullRefresh } from 'vant'

export default {
  components: {
    [Empty.name]: Empty,
    [List.name]: List,
    [PullRefresh.name]: PullRefresh
  },
  data() {
    return {
      current: 1,
      size: 10,
      loading: false,
      finished: false,
      refreshing: false,
      error: false,
      result: []
    }
  },
  created() {
    this.getData()
  },
  methods: {
    onLoad() {
      this.current = this.current + 1
      this.getData()
    },
    onRefresh() {
      this.current = 1
      this.result = []
      this.finished = false
      this.refreshing = true
      this.getData()
    },
    getData() {
      let params = {
        current: this.current,
        size: this.size,
        studentId: this.$route.query.info
      }
      this.$http.getEvaluateList(params).then(res => {
        let {records, current, pages} = res.data.result
        this.result = current > 1 ? [...this.result].concat(records) : records
        if (current >= pages) {
          this.finished = true
          this.loading = true
        }
        else {
          this.loading = false
          this.finished = false
        }
        this.refreshing = false
      }).catch(err => {
        console.log(err, 'err')
        this.$toast(err.data.message)
        this.refreshing = false
      })
    },
    goToDetail(item) {
      this.$router.push({name: 'evalateDetail', params: {id: item.id}})
    }
  }
}
</script>

<style lang="scss" scoped>
.evaluate-list {
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;
  padding: 16px 0;

  .item {
    background: white;
    margin: 0 16px 16px;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    cursor: pointer;

    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    }

    &:active {
      transform: translateY(0);
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .item-title {
      font-size: 17px;
      font-weight: 600;
      color: #1a1a1a;
      margin-bottom: 10px;
      line-height: 1.4;
    }

    .item-info {
      font-size: 14px;
      color: #666;
      margin-bottom: 6px;
      display: flex;
      align-items: center;

      &::before {
        content: "👨‍🏫";
        margin-right: 6px;
        font-size: 14px;
      }
    }

    .item-time {
      font-size: 14px;
      color: #999;
      display: flex;
      align-items: center;

      &::before {
        content: "🕒";
        margin-right: 6px;
        font-size: 14px;
      }
    }
  }

  .nodata {
    padding: 80px 20px;
  }
}

// 移动端适配
@media (max-width: 375px) {
  .evaluate-list {
    padding: 12px 0;

    .item {
      margin: 0 12px 12px;
      padding: 16px;
      border-radius: 10px;

      .item-title {
        font-size: 16px;
      }

      .item-info,
      .item-time {
        font-size: 13px;
      }
    }
  }
}
</style>
